<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <p>父组件中的:{{count}}</p>
      <counter :count.sync="count" @update:count="updateCount"></counter>
    </div>
    <script src="vue.js"></script>
    <script src="vue-router.js"></script>
    <script>
      Vue.component('counter',{
        props:['count'],
        template:`
          <div>
            <p>子组件中的:{{count}}</p>
            <button @click="increment">+</button>
          </div>
        `,
        methods:{
          increment(){
            //触发一个事件，事件的名称update:count,参数是新值
            this.$emit('update:count',this.count+1);
          }
        }
      });
      var vm = new Vue({
        el: "#app",
        data:{count:0},
        methods:{
          updateCount(val){
            this.count=val;
          }
        }
      });
    </script>
  </body>
</html>
